package com.kotlin.heimaplayer.adapter

import android.content.Context
import android.os.Bundle
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import com.kotlin.heimaplayer.model.CommonResultBean
import com.kotlin.heimaplayer.model.MvAreaBean
import com.kotlin.heimaplayer.ui.fragment.MvPagerFragment

class MvPagerAdapter(val context:Context?,val result: CommonResultBean<MvAreaBean>, fm: FragmentManager): FragmentPagerAdapter(fm) {



    override fun getItem(position: Int): Fragment {
        // 第一种传递数据方式
//        val fragment = MvPagerFragment()
        val bundle = Bundle()
        bundle.putString("args",result.data.sub.get(position).name)
//        fragment.arguments = bundle

        // 第二种
        val fragment = Fragment.instantiate(context!!,MvPagerFragment::class.java.name,bundle)

        return fragment
    }

    override fun getCount(): Int {
        return result.data.sub.subList(0,9).size
    }

    override fun getPageTitle(position: Int): CharSequence? {
        return result.data.sub.get(position).name
    }
}